﻿using B.MES.Customer.Application.Application;
using B.MES.Customer.Domain;
using B.MES.Customer.Domain.DTO;
using B.MES.Customer.Infrastructure.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using B.MES.Customer.Application.IApplication;

namespace B.MES.Customer.Application.Application
{
    /// <summary>
    /// RBAC服务层
    /// </summary>
    public class RBACApplication : BaseApplication<User>, IRBACApplication
    {
        /// <summary>
        /// RBAC仓储服务注入
        /// </summary>
        private readonly IRBACRepository _userRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="userRepository"> RBAC仓储服务</param>
        public RBACApplication(IRBACRepository userRepository) : base(userRepository)
        {
            _userRepository = userRepository;
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="loginInput">包含用户名和密码的登录信息</param>
        /// <returns>根据用户名查询到的用户信息</returns>
        public APIResult<OutPutLogin> UserLogin(InputLogin loginInput)
        {
            return _userRepository.UserLogin(loginInput);
        }
        /// <summary>
        /// MD5加密
        /// </summary>
        /// <param name="Password">需要加密的密码</param>
        /// <returns>加密之后的密码</returns>
        public object GetMD5Pwd(string Password)
        {
            return _userRepository.GetMD5Pwd(Password);
        }

        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="requestUserDTO"></param>
        /// <returns></returns>
        public APIResult<RequestUserDTO> AddUser(RequestUserDTO requestUserDTO)
        {
            return _userRepository.AddUser(requestUserDTO);
        }

        /// <summary>
        /// 获取所有角色
        /// </summary>
        /// <returns></returns>
        public List<Role> GetRole()
        {
            try
            {
                return _userRepository.GetRole();
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 单个删除（真删除）
        /// </summary>
        /// <param name="user_Id"></param>
        /// <returns></returns>
        public APIResult<User> UserDeleteData(string user_Id)
        {
            try
            {
               return _userRepository.UserDeleteData(user_Id);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public APIResult<List<User>> BatchDeleteData(List<User> list)
        {
            return _userRepository.BatchDeleteData(list);
        }

        /// <summary>
        /// 显示菜单
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List<MemuDTO> GetMemus(string userId)
        {
            return _userRepository.GetMemus(userId);
        }

        /// <summary>
        /// 显示全部菜单
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List<MemuDTO> GetMemus()
        {
            return _userRepository.GetMemus();
        }

        /// <summary>
        /// 用户查询+分页+显示
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public PageApiResut<User> GetUserListByKeyword(string? user_Name, string? u_Name, int page, int size)
        {
            return _userRepository.GetUserListByKeyword(user_Name, u_Name, page, size);
        }

        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="requestUserDTO"></param>
        /// <returns></returns>
        public APIResult<RequestUserDTO> UpdateUser(RequestUserDTO requestUserDTO)
        {
            try
            {
                return _userRepository.UpdateUser(requestUserDTO);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 用户反填
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public APIResult<RequestUserDTO> GetUserSel(string userId)
        {
            try
            {
                return _userRepository.GetUserSel(userId);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
